package com.trkj.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.trkj.dao.mybatis.IEquipPageDAO;
import com.trkj.dao.mybatis.IOfficeMapper;
import com.trkj.dao.mybatis.ISupplyMapper;
import com.trkj.pojos.Equip;
import com.trkj.pojos.Supply;
import com.trkj.pojos.Office;

@Service
public class EquipSoService {
	@Autowired
	private IEquipPageDAO equipPageDAO;
	@Autowired
	private IOfficeMapper iOfficeMapper;
	@Autowired
	private ISupplyMapper iSupplyMapper;
	
	public Map<String,Object> getEquip(int page,int rows,String where){
		 Page<Equip> p = PageHelper.startPage(page, rows, true);//分页
		 List<Equip> list=new ArrayList<>();
		 
		 Map<String,Object> name = new HashMap<>();
		 name.put("name", where);
		 if(where!=""){
			 list = equipPageDAO.selectEquipWhere(name);
		 }else{
		  list = equipPageDAO.selectAll();
		 }
		 List<Map<String,Object>> data=new ArrayList<>();
		 for (Equip equip : list) {	
			 Map<String,Object> e = new HashMap<>();
			 e.put("id", equip.getEquipId());
			 e.put("name", equip.getEdetailName3());
			 e.put("company", equip.getEquipComp3());
			 e.put("price", equip.getRdetailPrice3());
			 e.put("type", equip.getEquipType().getEtypeName());
			 data.add(e);
		}
		 
		Map<String,Object> map = new HashMap<>();
			map.put("total", p.getTotal());
			map.put("rows", data);
		return map;
	}
	
	public Map<String, Object> getSupply(int pageNum,int pageSize,String where){
		Page<Supply> p = PageHelper.startPage(pageNum, pageSize, true);
		List<Supply> list=new ArrayList<>();
		Map<String,Object> name = new HashMap<>();
		name.put("name", where);
		if(where!=""){
			list = iSupplyMapper.selectSupplyWhere(name);
		 	}else{
		 		list = iSupplyMapper.selectAll();
		 }
		 List<Map<String,Object>> data=new ArrayList<>();
		 for (Supply supply : list) {	
			 Map<String,Object> e = new HashMap<>();
			 e.put("id", supply.getSuppliesId());
			 e.put("name", supply.getSuppliesName());
			 e.put("company", supply.getSuppliesCompany());
			 e.put("price", supply.getSuppliesPrice());
			 e.put("type", supply.getSuppliesType().getStypeName());
			 data.add(e);
		}
		Map<String,Object> map = new HashMap<>();
		map.put("total", p.getTotal());
		map.put("rows", data);
		return map;
	}
	
	public Map<String, Object> getOffice(int pageNum,int pageSize,String where){
		Page<Office> p = PageHelper.startPage(pageNum, pageSize, true);
		List<Office> list = new ArrayList<>();
		Map<String,Object> name = new HashMap<>();
		name.put("name", where);
		if(where!=""){
			list = iOfficeMapper.selectOfficeWhere(name);
		 	}else{
		 		list = iOfficeMapper.selectOfficeAll();
		 }
		
		List<Map<String,Object>> data=new ArrayList<>();
		 for (Office office : list) {	
			 Map<String,Object> e = new HashMap<>();
			 e.put("id", office.getOfficeId());
			 e.put("name", office.getOfficeName());
			 e.put("company", office.getOfficeCompany());
			 e.put("price", office.getOfficePrice());
			 e.put("type", office.getOfficeType().getOftpName());
			 data.add(e);
		}
		Map<String, Object> map = new HashMap<>();
		map.put("total", p.getTotal());
		map.put("rows", data);		
		return map;
	}
}
